from clickhouse_driver import Client
from app.env import CLICKHOUSE_HOST, CLICKHOUSE_PORT, CLICKHOUSE_DB, CLICKHOUSE_USER, CLICKHOUSE_PASSWORD


class ClickHouseUtil(object):

    def __init__(self):
        client = Client(host=CLICKHOUSE_HOST, port=CLICKHOUSE_PORT, database=CLICKHOUSE_DB, user=CLICKHOUSE_USER,
                        password=CLICKHOUSE_PASSWORD)
        self.client = client

    def exec(self, sql_str):
        return self.client.execute(sql_str)

    def exec_pd(self, sql_str):
        return self.client.query_dataframe(sql_str)


if __name__ == '__main__':
    sql = 'select * from hbgs.kkxx_zyls limit 0, 1000'
    ans = ClickHouseUtil().exec(sql)
    # print(result)
    # client = Client(host='192.168.101.3', port='9000')
    # print(client)

    # ans = client.query_dataframe(sql)
    print(ans)
